package com.example.service.user.impl;

import com.example.mapper.UserMapper;
import com.example.pojo.User;
import com.example.dto.business.UserBusinessDTO;
import com.example.service.user.SearchService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lexin Huang
 */
@Service
public class SearchServiceImpl implements SearchService {

    private final UserMapper userMapper;

    public SearchServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public List<UserBusinessDTO> getUsersLike(String name) {
        List<User> queryRes = userMapper.selectUsernameLike(name);
        List<UserBusinessDTO> users = new ArrayList<>();
        if (null != queryRes) {
            for (User user : queryRes) {
                users.add(new UserBusinessDTO(user));
            }
        }
        return users;
    }


}
